local weiwei = fk.CreateSkill {
  name = "ls__weiwei",
  tags = { "Phase" }
}

Fk:loadTranslationTable{
  ["ls__weiwei"] = "卫威",
  [":ls__weiwei"] = "阶段技，你可移去中央区内所有黑色牌，视为使用【决斗】，若中央区内黑色牌较多，此【决斗】改为打出等量【杀】响应。",
  ["#ls__weiwei-prompt"] = "卫威：你可选择一名角色，视为对其使用【决斗】",

  ["$ls__shishi1"] = "阿瞒聚众来犯，吾一人可挡万敌！",
  ["$ls__shishi2"] = "勇绝河北，吾足以一柱擎天！",
  ["$ls__weiwei1"] = "阿瞒且寄汝首，待吾一骑取之！",
  ["$ls__weiwei2"] = "杀！尽歼贼败军之众！",
}

local DIY = require "packages/diy_utility/diy_utility"

weiwei:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#CenterArea")
end)

weiwei:addEffect("active", {
  anim_type = "offensive",
  prompt = "#ls__weiwei-prompt",
  max_phase_use_time = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    local card = Fk:cloneCard("lvshi__duel")
    return #selected == 0 and player:canUseTo(card, to_select)
  end,
  target_num = 1,
  card_num = 0,
  on_use = function(self, room, effect)
    local from = effect.from
    local to = effect.tos[1]
    local blacks = table.filter(DIY.getCenterCards(room), function (id) return Fk:getCardById(id).color == Card.Black end)
    if #blacks > 0 then
      DIY.removeCenterCards(from, blacks)
    end
    local use = {
      card = Fk:cloneCard("duel"),
      from = from,
      tos = effect.tos,
      extra_data = { shuangxiong = #blacks },
    }
    use.card.skillName = self.name
    room:useCard(use)
  end,
})

weiwei:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(weiwei.name) and data.card.trueName == "duel"
    and data.extra_data and data.extra_data.shuangxiong > #table.filter(DIY.getCenterCards(player.room),
    function (id) return Fk:getCardById(id).color == Card.Red end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local n = data.extra_data.shuangxiong
    data:setResponseTimes(n, player)
    data:setResponseTimes(n, data.to)
  end,
})

return weiwei